<h1>New Contest</h1>

<table class="cs2">
  <tr>
    <td>

<% form_for(@contest) do |f| -%>
  <%= f.error_messages %>
    <legend>Create New Contest</legend>
    <p>
      <%= f.label :name %><br />
      <%= f.text_field :name %>
    </p>

    <p>
      <%= f.label :start_time %><br />
      <%= f.datetime_select :start_time%>
    </p>

    <p>
      <%= f.label :end_time %><br />
      <%= f.datetime_select :end_time%>
    </p>

    <ul>
    </ul>

    <table name="Problems:" id="problems">
      <% @problem_difficulties.each do |difficulty, value| -%>

      <tr id="<%= difficulty %>">
        <td>
          <label>Difficulty</label>
        </td>
        <td>
          <select name="<%= difficulty %>">
            <% for i in (1..5) -%>
              <option value="<%= i %>" <%= "selected" if i.to_s == value%>><%= i %></option>
            <% end -%>
          </select>
        </td>
        <td>
          <%= link_to_remote "Remove",
            :url => {:action => 'remove_difficulty'},
            :update => difficulty %>
        </td>
      </tr>

      <% end -%>
    </table>

    <%= javascript_tag "var difficulty_index = #{@difficulty_index};" %>
    <%= button_to_remote "Generate Random Problem",
      :url => {:action => 'add_difficulty'}, :with => "'difficulty_index='+(difficulty_index++)" %>

<p><%= f.submit "Create" %></p>
<% end -%>


<%= link_to 'Back', contests_path %>
